//////////////////////////////////////////
//
//	FlexInc. 2011
//	http://www.loziosecchi.it/flex_inc
//	http://twitter.com/loziosecchi
//
//////////////////////////////////////////

package flexInc.spark.effects
{
	import flash.geom.Point;
	import flash.utils.ByteArray;
	
	import mx.effects.IEffectInstance;
	
	import spark.effects.AnimateTransitionShader;
	
	/**
	 *  The Wipe effect uses Pixel Bender, which is not supported
	 *  for AIR mobile applications.
	 */
	[DiscouragedForProfile("mobileDevice")]

	/**
	 *  The CircleWipe effect performs a bitmap transition effect by running a
	 *  <i>directional circular wipe</i> between the first and second bitmaps.
	 *  This wipe exposes the second bitmap over the course of the 
	 *  animation in a direction indicated by the <code>direction</code>
	 *  property.
	 * 
	 *  <p>A pixel-shader program loaded by the effect
	 *  runs the underlying bitmap effect. 
	 *  If you want to use 
	 *  a different CircleWipe behavior, you can specify a custom pixel-shader program. 
	 *  The pixel-shader program must adhere to the constraints 
	 *  specified for the <code>shaderByteCode</code>
	 *  property of AnimateTransitionShader class, and supply three additional
	 *  parameters. 
	 *  The extra parameters required by the CircleWipe shader 
	 *  are:</p>
	 *
	 *  <ul>
	 *    <li>An int <code>direction</code> parameter, 
	 *  whose value means the same as the related String property
	 *  in the CircleWipe class.</li>
	 *    <li>Two floating point parameters: 
	 *  <code>imageWidth</code> and <code>imageHeight</code>. </li>
	 *  </ul>
	 *
	 *  <p>All of these parameters are set on the shader when the effect starts playing,
	 *  so the parameters need to exist and do something appropriate in
	 *  order for the effect to function correctly.</p>
	 *  
	 *  @see flexInc.spark.effects.CircleWipeDirection
	 *  @see spark.effects.AnimateTransitionShader
	 *  @see spark.effects.AnimateTransitionShader#shaderByteCode
	 *  
	 *  @langversion 3.0
	 *  @playerversion Flash 10
	 *  @playerversion AIR 1.5
	 *  @productversion Flex 4
	 */
	public class Push extends AnimateTransitionShader
	{
		[Embed(source="PushDown.pbj", mimeType="application/octet-stream")]
		private static var PushDownShaderClass:Class;
		private static var pushDownShaderCode:ByteArray = new PushDownShaderClass();
		[Embed(source="PushUp.pbj", mimeType="application/octet-stream")]
		private static var PushUpShaderClass:Class;
		private static var pushUpShaderCode:ByteArray = new PushUpShaderClass();
		[Embed(source="PushLeft.pbj", mimeType="application/octet-stream")]
		private static var PushLeftShaderClass:Class;
		private static var pushLeftShaderCode:ByteArray = new PushLeftShaderClass();
		[Embed(source="PushRight.pbj", mimeType="application/octet-stream")]
		private static var PushRightShaderClass:Class;
		private static var pushRightShaderCode:ByteArray = new PushRightShaderClass();

		[Inspectable(enumeration="left,right,up,down", defaultValue="right")]
		/**
		 *  The direction that the wipe moves during the animation: 
		 *  <code>PushDirection.RIGHT</code>, <code>PushDirection.LEFT</code>, 
		 *  <code>PushDirection.UP</code>, or <code>PushDirection.DOWN</code>. 
		 *
		 *  @default PushDirection.RIGHT
		 *
		 *  @see PushDirection#RIGHT
		 *  @see PushDirection#UP
		 *  @see PushDirection#LEFT
		 *  @see PushDirection#DOWN
		 *  
		 *  @langversion 3.0
		 *  @playerversion Flash 10
		 *  @playerversion AIR 1.5
		 *  @productversion Flex 4
		 */
		public var direction:String = PushDirection.RIGHT;

		/**
		 *  Constructor. 
		 *
		 *  @param target The Object to animate with this effect.  
		 *
		 *  @langversion 3.0
		 *  @playerversion Flash 10
		 *  @playerversion AIR 1.5
		 *  @productversion Flex 4
		 */
		public function Push(target:Object=null)
		{
			super(target);
		}

		/**
		 *  @private
		 */
		override protected function initInstance(instance:IEffectInstance):void
		{
			switch (direction)
			{
				case PushDirection.RIGHT:
					shaderByteCode = pushRightShaderCode;
					break;
				case PushDirection.LEFT:
					shaderByteCode = pushLeftShaderCode;
					break;
				case PushDirection.UP:
					shaderByteCode = pushUpShaderCode;
					break;
				case PushDirection.DOWN:
					shaderByteCode = pushDownShaderCode;
					break;
			}
			
			super.initInstance(instance);
		}
	}
}